package com.bodu.task;

import com.bodu.core.task.BoduQuartzJobBean;
import com.bodu.exchange.entity.po.CnPaijiaPo;
import com.bodu.system.service.CronTriggersService;
import com.bodu.system.service.CronTriggersSynchroTimeService;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author Administrator
 */
@Component
@Slf4j
public class ExchangeJobTask extends BoduQuartzJobBean {
    @Autowired
    private CronTriggersService cronTriggersService;

    @Autowired
    private CronTriggersSynchroTimeService cronTriggersSynchroTimeService;

    @Override
    protected CronTriggersService getCronTriggersService() {
        return cronTriggersService;
    }

    @Override
    protected CronTriggersSynchroTimeService getcronTriggersSynchroTimeService() {
        return cronTriggersSynchroTimeService;
    }

    @Override
    public void task(JobExecutionContext jobExecutionContext) {
        
    }

    public static void main(String[] args) throws IOException {
        String url = "https://www.boc.cn/sourcedb/whpj/";
        Connection connect = Jsoup.connect(url);

        Document document = connect.get();

        Elements elements = document.body().select("div table tr");
//        货币名称	现汇买入价	现钞买入价	现汇卖出价	现钞卖出价	中行折算价	发布日期	发布时间
        StringBuffer s = new StringBuffer("");
        for (Element e : elements) {
            StringBuffer sb = new StringBuffer();
            
            CnPaijiaPo cnPaijiaPo = new CnPaijiaPo();
            cnPaijiaPo.setCoinBuyHuiPrice(e.select("td").get(0).text());
            cnPaijiaPo.setCoinBuyChaoPrice(e.select("td").get(1).text());
            cnPaijiaPo.setCoinSaleHuiPrice(e.select("td").get(2).text());
            cnPaijiaPo.setCoinSaleChaoPrice(e.select("td").get(3).text());
            cnPaijiaPo.setMiddlePrice(e.select("td").get(4).text());
            cnPaijiaPo.setDelayDate(e.select("td").get(5).text());
            cnPaijiaPo.setDelayTime(e.select("td").get(6).text());
             
        }
        System.out.println(s.toString());
//        System.out.println(document.body().text());
    }
}
